#!/usr/bin/env python
"""
重置 admin 用户密码的脚本
"""
import os
import django

# 设置 Django 环境
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'pecco_backend.settings')
django.setup()

from django.contrib.auth import get_user_model

User = get_user_model()

# 查找或创建 admin 用户
try:
    user = User.objects.get(username='admin')
    print(f"找到用户: {user.username}")
except User.DoesNotExist:
    user = User.objects.create_superuser(
        username='admin',
        email='admin@pecco.com',
        password='admin123'
    )
    print(f"创建新用户: {user.username}")

# 重置密码
user.set_password('admin123')
user.is_staff = True
user.is_superuser = True
user.save()

print("=" * 50)
print("✅ 密码重置成功！")
print("=" * 50)
print("登录信息:")
print(f"  用户名: admin")
print(f"  密码: admin123")
print("=" * 50)
print("请访问: http://localhost:5174/")
print("=" * 50)

